#include "Tank.h"

Tank::Tank(int id, int posX, int posY, CardinalDirection direction, ActionType action, unsigned progress)
{
    m_id = id;
    m_pos.x = posX;
    m_pos.y = posY;
    m_tankType = PLAYER;
    m_direction = eNorth;
    m_speed = 2;
    m_completeness = progress;

    if (m_tankType == PLAYER)
    {
    m_texture = QSharedPointer<QGraphicsPixmapItem>(m_scene->addPixmap(QPixmap(":/res/tank.png")));
    }
    else
    {
    m_texture = QSharedPointer<QGraphicsPixmapItem>(m_scene->addPixmap(QPixmap(":/res/enemy.png")));
    }

    SetImagePosition(QPointF(m_pos.x*6, m_pos.y*6)); // mult by cell size
    SetImageRotation(0);
}

qreal Tank::AngleFromDirection(DynamicObject::CardinalDirection direction)
{
    switch(direction)
    {
    case eNorth:
        return 0;
        break;
    case eEast:
        return 90;
        break;
    case eSouth:
        return 180;
        break;
    case eWest:
        return 270;
        break;
    }
}

void Tank::move()
{
    if (m_currentAction == eStaying)
    {
        m_currentAction = eMoving;
    }
}

void Tank::destroy()
{
    //actions to do when tank's health == 0
}

void Tank::render()
{
    m_view->show();
}

void Tank::turn(char direction)
{
    switch(direction)
    {
    case 'N':
        m_direction = eNorth;
        break;
    case 'E':
        m_direction = eEast;
        break;
    case 'S':
        m_direction = eSouth;
        break;
    case 'W':
        m_direction = eWest;
        break;
    }
}

void Tank::hit()
{
    --m_healthLvl;
}
